﻿@model ADIGRE.MVC3.Web.Controllers.ViewModels.CultoViewModel
<table id="tDizimo" style="width: 100%; text-align: center;">
    @{ bool th = false;}
    @for (int i = 0; i < Model.Dizimos.Count(); i++)
    {

        if (!Model.Dizimos.ElementAt(i).IsExcluido && !th)
        {
            th = true;
        <tr>
            <th style="width: 25%;">
                <label>
                    Dizimista</label>
            </th>
            <th style="width: 20%;">
                <label>
                    Valor</label>
            </th>
            <th style="width: 15%;">
                <label>
                    Data Ref.</label>
            </th>
            <th>
                <label>
                    Obs</label>
            </th>
            <th style="width: 40px;">
            </th>
        </tr>
        }
 
        <tr id='@string.Format("dizimo-{0}", i)' style="display:@string.Format("{0}", Model.Dizimos.ElementAt(i).IsExcluido ? "none" : "");">
            <td>
                @Html.Hidden(string.Format("Dizimos[{0}].IsEntrada", i), Model.Dizimos.ElementAt(i).IsEntrada)
                @Html.Hidden(string.Format("Dizimos[{0}].EnumLancamento", i), Model.Dizimos.ElementAt(i).EnumLancamento)
                @Html.Hidden(string.Format("Dizimos[{0}].IsExcluido", i), Model.Dizimos.ElementAt(i).IsExcluido, new { @class = "IsExcluido" })
                @Html.DropDownList(string.Format("Dizimos[{0}].Dizimista.Id", i), (IEnumerable<SelectListItem>)ViewBag.Dizimistas, "Selecione", null)
            </td>
            <td>
                @Html.TextBox(string.Format("Dizimos[{0}].VlLancamento", i), Model.Dizimos.ElementAt(i).VlLancamento, new { @class = "decimal" })
            </td>
            <td>
                @Html.TextBox(string.Format("Dizimos[{0}].DtReferencia", i), Model.Dizimos.ElementAt(i).DtReferencia, new { @class = "datepicker" })
            </td>
            <td>
                @Html.TextBox(string.Format("Dizimos[{0}].DsObservacao", i), Model.Dizimos.ElementAt(i).DsObservacao, new { style = "width: 90%;"})
            </td>
            <td>
                <input class="remove-dizimo icon-remove" type="button" title="Remover Dízimo"  onclick="ExcluirDizimo('@string.Format("dizimo-{0}", i)')"/>
            </td>
        </tr>   
    }
</table>

<script type="text/javascript">
    $(document).ready(function () {

        $.datepicker.setDefaults($.datepicker.regional[""]);
        $(".datepicker").datepicker($.datepicker.regional["pt-BR"]);
        $(".datepicker").datepicker({
            inline: true,
            changeMonth: true,
            changeYear: true
        });

        jQuery(function ($) {
            $('.decimal').setMask("decimal");
            $('.datepicker').setMask("date");
            $('.integer').setMask("999");
        });
    });

    function MoneyToFloat(valor) {
        return parseFloat(getNum(valor.replace(/\s/g, "").replace(".", "").replace(".", "").replace(".", "").replace(".", "").replace(",", ".")));
    }

    function getNum(num) {
        if (num == '' || (num + 0) == 0)
            num = "0";
        return num;
    }

    function parseMoney(num) {
        var x = 0;

        num = getNum(num);

        if (num < 0) {
            num = Math.abs(num);
            x = 1;
        }
        if (isNaN(num))
            num = "0";

        cents = Math.floor((num * 100 + 0.5) % 100);
        num = Math.floor((num * 100 + 0.5) / 100).toString();

        if (cents < 10)
            cents = "0" + cents;

        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3));

        ret = num + ',' + cents;

        if (x == 1)
            ret = ' - ' + ret;

        return ret;
    }

</script>